﻿using MySql.Data.MySqlClient;
using Mysqlx.Crud;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KeDa2025_
{
    public partial class rizhi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnPublic_Click(object sender, EventArgs e)
        {
            // 日志发布   insert
            string title=txtTitle.Text;
            string detail = txtDetail.Value;
            DataRow userRow = (DataRow)Session["User"];
            int user_id = Convert.ToInt32(userRow["id"]);
            string sql = string.Format(@"INSERT INTO notes (title, detail, user_id, create_time,read_count) VALUES ('{0}', '{1}', '{2}', '{3}',0)",
                           title, detail, user_id, DateTime.Now);
        
           
            // 建立数据库连接
            string connectionString = "server=localhost;user id=zmy2;password=zmy20020525;database=forum;";
            MySqlConnection connection = new MySqlConnection(connectionString);

            // 创建MySQLCommand对象
            MySqlCommand cmd = new MySqlCommand(sql, connection);

            // 执行SQL语句并获取结果
            connection.Open();
            int flag = cmd.ExecuteNonQuery();
            connection.Close();
            if (flag > 0)
                Response.Write("<script>alert('发布成功');window.location.href='index.aspx'</script>");





        }
    }
    }
